#pragma 
#include<pthread.h>
#include<iostream>
#include<functional>
using namespace std;
using func_t = function<void(const string name)>;
class Thread
{
public:
    Thread(std::string name,func_t func)
    {
        this->name = name;
        this->func = func;
    }
    void Excute()
    {
        is_running = true;
        func(name);
        is_running = false;
    }
    std::string Status()
    {
        if(is_running)
            return "running";
        else
            return "sleep";
    }
    static void* ThreadRoutime(void* args)
    {
        Thread *self = static_cast<Thread *>(args);
        self->Excute();
        return nullptr;
    }
    bool Start()
    {
        int n=::pthread_create(&tid, nullptr, ThreadRoutime, this);
        if(n!=0)
            return false;
        else
            return true;
    }
    void Stop()
    {
        if(is_running)
        {
            is_running = false;
            ::pthread_cancel(tid);
        }
    }
    void Join()
    {
        if(is_running)
        {
            ::pthread_join(tid, nullptr);
        }
    }
    ~Thread()
    {
        Stop();
    }

private:
    std::string name;
    pthread_t tid;
    bool is_running;
    func_t func;
};